﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoolERP_Entities;

namespace CoolERP_DAL
{
    public interface ICGDMXBDAL : IDAL<CGDMXB>
    {
        List<CGDMXBModel> GetCGDMXB(Guid CGDID);
    }

    public class CGDMXBDAL : BaseDAL<CGDMXB>, ICGDMXBDAL
    {
        public CGDMXBDAL(IUnitOfWork context)
            : base(context)
        {
        }

        public List<CGDMXBModel> GetCGDMXB(Guid CGDID)
        {
            var result = from mx in dataContext.CGDMXB.Where(t => t.CGDID == CGDID)
                         join wl in dataContext.ZL_WL on mx.WPID equals wl.ID
                         join ys in dataContext.CS_YS on new { YSLXBH = wl.YSLXBH, YSBH = wl.YSBH } equals new { YSLXBH = ys.YSLXBH, YSBH = ys.BH }
                         join dw in dataContext.CS_JBDW on mx.DWBH equals dw.BH
                         select new CGDMXBModel
                         {
                             ID = mx.ID,
                             WPID = mx.WPID,
                             WPLX = mx.WPLX,
                             BH = wl.BH,
                             MC = wl.MC,
                             GG = wl.GG,
                             YS = ys.MC,
                             DWBH = mx.DWBH,
                             DWMC = dw.MC,
                             SL = mx.SL,
                             DJ = mx.DJ,
                             CGDID = mx.CGDID
                         };
            return result.ToList();
        }
    }
}
